package com.ruoyi.app.controller.shop.service.impl;

import com.ruoyi.app.controller.shop.mapper.IShopMapper;
import com.ruoyi.app.controller.shop.service.IShopService;
import com.ruoyi.common.entity.VO.shop.ShopSearchVO;
import com.ruoyi.common.entity.VO.shop.ShopVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;

@Service
public class ShopServiceImpl implements IShopService {

    @Resource
    private IShopMapper shopMapper;

    @Override
    public ShopVO getShopGeneralInfo(ShopSearchVO shopSearchVO) {
        ShopVO shopGeneraInfo;
        if (null != shopSearchVO.getLat() && null != shopSearchVO.getLon()) {
            shopGeneraInfo = shopMapper.getShopGeneralInfoWithDistance(shopSearchVO.getShopId(), shopSearchVO.getLat(), shopSearchVO.getLon());
            BigDecimal bg = BigDecimal.valueOf(shopGeneraInfo.getDistance());
            double distance = bg.setScale(2, RoundingMode.HALF_UP).doubleValue();
            shopGeneraInfo.setDistance(distance);
        } else {
            shopGeneraInfo = shopMapper.getShopGeneralInfo(shopSearchVO.getShopId());
        }
        return shopGeneraInfo;
    }
}
